import 'package:flutter/material.dart';

class SliderView extends StatefulWidget {
  var data;
  SliderView(data) {
    this.data = data;
  }

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new SliderViewState(data);
  }
}

class SliderViewState extends State<SliderView>
    with SingleTickerProviderStateMixin {
  TabController tabController;
  List sliderData;
  SliderViewState(data) {
    sliderData = data;
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    tabController = new TabController(
        length: sliderData == null ? 0 : sliderData.length, vsync: this);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    List<Widget> items = [];
    if (sliderData != null && sliderData.length > 0) {
      for (var i = 0; i < sliderData.length; i++) {
        var item = sliderData[i];
        var imgUrl = item["imgUrl"];
        var title = item["title"];
        //var detailUrl = item["detailUrl"];
        items.add(new GestureDetector(
          onTap: () {
            //
          },
          child: new Stack(
            children: <Widget>[
              new Container(width: MediaQuery.of(context).size.width,
              child: new Image.network(imgUrl,fit: BoxFit.fitWidth,),),              
              new Container(
                width: MediaQuery.of(context).size.width,
                color: const Color(0x50000000),
                child: new Padding(
                  padding: const EdgeInsets.all(6.0),
                  child: new Text(
                    title,
                    style: new TextStyle(
                      color: Colors.white,
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ));
      }
      return new TabBarView(
        controller: tabController,
        children: items,
      );
    }
  }
}
